/*package cn.chaohi.common;

import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Aspect
@Component
public class WebLogAspect {

    private Logger logger = Logger.getLogger(WebLogAspect.class);

    //捕获所有存在于controller中和service中的异常
    @Pointcut("execution(public * cn.chaohi.service.*.*(..)) || execution(public * cn.chaohi.controller.*.*(..))")
    public void webLog() {
    }

    @Before("webLog()")
    public void doBefore(JoinPoint joinPoint) {

        // 接收到请求，记录请求内容
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        // 记录下请求内容
        logger.info("Request URL : " + request.getRequestURL().toString());
        // IP address
        logger.info("IP : " + request.getRemoteAddr());
        // IP address
        logger.info("Class_Method : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    }

    @AfterThrowing(pointcut = "webLog()", throwing = "e")
    public void handle(JoinPoint joinPoint, Exception e) {
    	Signature signature = joinPoint.getSignature();
    	String errorMessage = "错误位置 : " + signature.getDeclaringTypeName() + "." + signature.getName();
    	if(null != e) {
    		errorMessage = errorMessage + ". 异常信息 ---> " + e.getMessage();    		
    	}
    	logger.error(errorMessage);
    }
}*/